<template>
  <div class="app-container home">
    <el-form
      ref="form"
      :model="form"
      :rules="rules"
      :inline="true"
      size="small"
      label-width="120px"
    >
      <el-form-item label="辅导科目" prop="subject">
        <el-input v-model="form.subject" placeholder="请输入辅导科目" />
      </el-form-item>
      <el-form-item label="年级" prop="grade">
        <el-input v-model="form.grade" placeholder="请输入年级" />
      </el-form-item>
      <el-form-item label="地点" prop="location">
        <el-input v-model="form.location" placeholder="请输入地点" />
      </el-form-item>
      <el-form-item label="需求描述" prop="description">
        <el-input
          v-model="form.description"
          type="textarea"
          placeholder="请输入内容"
        />
      </el-form-item>
      <el-form-item label="预算" prop="budget">
        <el-input v-model="form.budget" placeholder="请输入预算，单位为元" />
      </el-form-item>
      <el-form-item label="每周次数" prop="availability">
        <!-- <el-input
            v-model="form.availability"
            placeholder="请输入可上课时间，例如：周一至周五下午"
          /> -->
        <el-input
          v-model="form.availability"
          type="number"
          placeholder="请输入可上课次数"
        />
      </el-form-item>
      <el-form-item label="课程时间" prop="duration">
        <!-- duration -->
        <el-input
          v-model="form.duration"
          type="number"
          placeholder="请输入课程时长，例如：每次2小时"
        />
      </el-form-item>
      <el-form-item label="备注" prop="additionalRequirements">
        <el-input
          v-model="form.additionalRequirements"
          type="textarea"
          placeholder="请输入内容"
        />
      </el-form-item>
      <!-- <el-form-item label="发布时间" prop="createdAt">
          <el-date-picker
            clearable
            v-model="form.createdAt"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择发布时间"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="最后更新时间" prop="updatedAt">
          <el-date-picker
            clearable
            v-model="form.updatedAt"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择最后更新时间"
          >
          </el-date-picker>
        </el-form-item> -->
      <!-- <el-form-item label="需求状态" prop="status">
          <el-radio-group v-model="form.status">
            <el-radio
              v-for="dict in student_status"
              :key="dict.value"
              :label="dict.value"
              >{{ dict.label }}</el-radio
            >
          </el-radio-group>
        </el-form-item> -->
      <!-- <el-form-item label="用户名称" prop="userName">
          <el-input v-model="form.userName" placeholder="请输入用户名称" />
        </el-form-item> -->
    </el-form>
  </div>
</template>

<script>
import {
  listRequests,
  getRequests,
  delRequests,
  addRequests,
  updateRequests,
} from '@/api/system/requests'
import store from '@/store'

export default {
  props: {
    student_status: {
      type: Array,
      default: () => [],
    },
    rules: {
      type: Object,
      default: () => {},
    },
  },
  data() {
    return {
      form: {},
    }
  },
  methods: {
    getForm(id) {
      getRequests(id).then((response) => {
        this.form = response.data
      })
    },
    submitForm() {
      this.$refs['form'].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            updateRequests(this.form).then((response) => {
              this.form = {}
              this.$emit('openFalse')
              this.$modal.msgSuccess('修改成功')
            })
          } else {
            this.form.userId = store.getters.id
            this.form.userName = store.getters.name
            addRequests(this.form).then((response) => {
              this.$emit('openFalse')
              this.form = {}
              this.$modal.msgSuccess('新增成功')
            })
          }
        }
      })
    },
  },
}
</script>

<style lang="scss" scoped></style>
